<?php

/**
 * 网站默认控制器
 *
 * @author JiangJian <silverd@sohu.com>
 * $Id: Index.php 156 2012-11-08 01:37:15Z silverd30@gmail.com $
 */

class Controller_Index extends Controller_Abstract
{
    public function init()
    {
        if ($this->isAjax()) {
            $this->autoRender = false;
        }
    }

    // 以下几个URL等价
    // http://xianglephp/
    // http://xianglephp/index
    // http://xianglephp/index/index
    public function indexAction()
    {
        exit('hello world index');
    }

    // http://xianglephp/index/tpl
    public function tplAction()
    {
        echo 'hello world with tpl';
    }

    // http://xianglephp/index/no-layout
    public function noLayoutAction()
    {
        // 设置不需要布局
        $this->layout = null;
    }

    // http://xianglephp/index/no-tpl
    public function noTplAction()
    {
        echo 'without tpl included';

        // return false 表示不自动加载视图模板
        return false;
    }

    // 以下几个URL等价
    // http://xianglephp/index/params/?k1=v1&k2=v2&k3=v3
    // http://xianglephp/index/params/k1/v1/k2/v2/k3/v3
    public function paramsAction()
    {
        var_dump($this->get('k1'));
        var_dump($this->get('k2'));
        var_dump($this->get('k3'));
        var_dump($this->getParams());

        // return false 表示不自动加载视图模板
        return false;
    }

    public function forwardAction()
    {
        echo 'hello forwardAction <br />';

        $this->forward('Index', 'forwardTarget', array('page' => 1));

        return false;
    }

    public function forwardTargetAction()
    {
        echo 'hello forwardTargetAction';
    }
}